﻿Imports System.Data.OleDb

Public Class BlockUser
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try

            If (Not Page.IsPostBack) Then
                btnBlock.Visible = False
                btnUnblock.Visible = False
            End If

        Catch ex As Exception

        End Try
    End Sub

    Protected Sub grvUsers_SelectedIndexChanged(sender As Object, e As EventArgs) Handles grvUsers.SelectedIndexChanged
        Try

        
        Dim getProfile As ProfilesManagement = New ProfilesManagement()
        Dim dr As OleDbDataReader = getProfile.SelectProfileByUserID(Convert.ToInt32(grvUsers.SelectedValue))

        Dim blocked As Boolean = False

        If dr.HasRows Then
            dr.Read()
            If Not IsDBNull(dr("ProfileBlocked")) Then blocked = dr("ProfileBlocked")
        End If




        If (blocked = False) Then
            btnBlock.Visible = True
            btnUnblock.Visible = False

        Else
            btnBlock.Visible = False
            btnUnblock.Visible = True
        End If

        Catch ex As Exception

        End Try

    End Sub

    Protected Sub btnBlock_Click(sender As Object, e As EventArgs) Handles btnBlock.Click
        Try

            Dim block As ProfilesManagement = New ProfilesManagement()
            block.EditProfileBlockByUserID(Convert.ToInt32(grvUsers.SelectedValue), True)
            lblMessage.Text = "User blocked"
            grvUsers.DataBind()

            btnBlock.Visible = False
            btnUnblock.Visible = True

        Catch ex As Exception

        End Try
    End Sub

    Protected Sub btnUnblock_Click(sender As Object, e As EventArgs) Handles btnUnblock.Click
        Try

            Dim unblock As ProfilesManagement = New ProfilesManagement()
            unblock.EditProfileBlockByUserID(Convert.ToInt32(grvUsers.SelectedValue), False)
            lblMessage.Text = "User unblocked"
            grvUsers.DataBind()

            btnBlock.Visible = True
            btnUnblock.Visible = False

        Catch ex As Exception

        End Try
    End Sub
End Class